$(() => {
    let target = $(".cat-types");
    let data = getTableIndexValues('basic_info', 'color');
    data['所有'] = -1;
    for (let name in data) {
        target.append(`<span class="module s-module" style="background-image: url(/public/img/cloud-cat/${name}.jpg)"
            onclick="goCatList(this)" data-type=${data[name]}></span>`);/*<span>${name}</span>*/
        //<img src="/public/img/cloud-cat/${name}.jpg">
    }
});

function goCatList(target) {
    let type = $(target).attr("data-type");
    let status = $(target).parents(".main-content").attr("data-status");
    window.location.href = `/public/cat_list.html?type=${type}&status=${status}`;
}

async function onScrollBottom() {//刷新帖子
    const __errorHandleMe = (obj, err, msg) => {
        $("#thread_content").append(`<span><h1>${err}</h1>${msg}</span>`);
        page_me--;
    };
    let content = $("#main-content>.main-content.active");
    if (content.data('thread-page-end')) return;
    let type = content.attr('data-status');
    let page = content.data('thread-page') || 0;
    content.data('thread-page', page + 1);
    await login_check();
    let result = await $.get('/threads/list', { type: 'new', index: type, page: page });
    let target = content.children('.thread_content');
    if (page == 0) target.html('');
    if (!result.success) return __errorHandleMe('meThreadListError', result.err);
    result = result.result;
    if (!(result.length > 0)) content.data('thread-page-end', true);
    let users = new Set();
    for (let i in result) {
        i = toRealName(result[i]);
        users.add(i.uid);
        let ele = `<a href="/public/threads.html?tid=${i.id}" class="module m-module thread user-id-${i.uid}"><img class="sketch"src="/img/thread/${i.pid}" /><img class="userHead" src="https://placehold.it/256x256&text=USER"><span class="user">--</span><span class="description">${i.title}</span><span class="love"><svg class="icon"aria-hidden="true"><use xlink:href="#icon-heart"></use></svg><span class="love-amount">${i.like}</span></span></a>`;
        target.append(ele);
    }
    users.forEach(id => {
        $.get('/user/getUserInfo/' + id, r => $(`.user-id-${id} .user`).html(r.success ? (r = r.result, r.nick || r.name) : r.err));
        $.get('/img/user?uid=' + id, (r, s, x) => {
            let type = (x.getResponseHeader('Content-Type') || "").trim().toLowerCase(),
                t = $(`.user-id-${id} .userHead`);
            if (type === 'text/plain') t.replaceWith(`<svg class="icon userHead"aria-hidden="true"><use xlink:href="#icon-${r}"></use></svg>`);
            else t.attr('src', r);
        });
    });
}